import * as proxy from '../proxy';
import ServiceBase from '../base';
import {CommentPageProxy} from '../proxies/comment--page-proxy';
import {CommentArrayProxy, CommentProxy} from '../proxies/comment-proxy';
import {CommentReplyProxy} from '../proxies/comment-reply-proxy';

class CommentsService extends ServiceBase {
    addComment = (data) => {
        let promise = super.post({
            url: `/projects/${data.projectId}/comments`,
            data,
        });
        return proxy.httpResultProxy(promise, CommentProxy);
    };
    getProjectComments = (data) => {
        let promise = super.get({
            url: `/projects/${data.projectId}/comments`,
        });
        return proxy.httpResultProxy(promise, CommentPageProxy);
    };
    searchComments = (data) => {
        let promise = super.post({
            url: `/projects/${data.projectId}/comments/batch`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, CommentArrayProxy);
    };
    getComments = (data) => {
        let promise = super.get({
            url: `/projects/${data.projectId}/comments/search`,
            params: data,
        });
        return proxy.httpResultProxy(promise, CommentPageProxy);
    };
    deleteComment = (data) => {
        let promise = super.delete({
            url: `/projects/${data.projectId}/comments/${data.commentId}`,
        });
        return proxy.httpResultProxy(promise);
    };
    updateComment = (data) => {
        let promise = super.put({
            url: `/projects/${data.projectId}/comments/${data.commentId}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, CommentProxy);
    };
    changeCommentStates = (data) => {
        let promise = super.put({
            url: `/projects/${data.projectId}/comments/${data.commentId}/state`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    addResponse = (data) => {
        let promise = super.post({
            url: `/projects/${data.projectId}/comments/${data.commentId}/replies`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, CommentReplyProxy);
    };
    deleteReply = (data) => {
        let promise = super.delete({
            url: `/projects/${data.projectId}/comments/${data.commentId}/replies/${data.replyId}`,
        });
        return proxy.httpResultProxy(promise);
    };
    updateReply = (data) => {
        let promise = super.put({
            url: `/projects/${data.projectId}/comments/${data.commentId}/replies/${data.replyId}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, CommentReplyProxy);
    };
    updateReplyState = (data) => {
        let promise = super.put({
            url: `/projects/${data.projectId}/comments/${data.commentId}/replies/${data.replyId}/state`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
}

export {CommentsService};
